/**
 * Created by chenweicheng on 1/3/2017.
 */
/**
 * Created by Administrator on 2016/12/20 0020.
 */

import React, {Component} from 'react';
import {AppRegistry, View, Text, ScrollView, Image, StyleSheet, TouchableHighlight} from 'react-native';
import DBManager from '../DBManager';

export default class TestDBManager extends Component {

    constructor(props) {
        super(props)
        this.state = {requetResult: ''}
    }



    handleSaveLocal() {
        DBManager.saveLocally("testkey1", "testvalue2").then(() => {
            console.log("saveLocally success");
        }, (error) => {
            console.log("saveLocally fail" + error)
        });

    }

    handleSaveDictLocally() {
        DBManager.saveDictLocally('testkey4', {'a': '123', 'b': 456}).then(() => {
            console.log('saveDictLocally success')
        }, (error) => {
            console.log("saveDictLocally fail" + error)
        });
    }

    handlerReadLocally() {
        DBManager.readLocally('testkey1').then((result) => {
            console.log('readLocally success = ' + result)
        }, (error) => {
            console.log("readLocally fail" + error)
        });

    }

    handlerReadMapLocally() {
        DBManager.readLocally('testkey4').then((result) => {
            if (result == "") {
                console.log('no saved data');
            } else {
                console.log('ReadMapLocally success', JSON.parse(result));
            }

        }, (error) => {
            console.log("readLocally fail" + error)
        });

    }

    render() {
        return (
            <View style={styles.container}>
                <TouchableHighlight style={{padding: 20, backgroundColor: '#ccc'}}
                                    onPress={() =>this.handleSaveLocal()  }>
                    <Text>SaveLocal</Text>
                </TouchableHighlight>
                <TouchableHighlight style={{padding: 20, backgroundColor: '#ccc'}}
                                    onPress={() =>this.handleSaveDictLocally()  }>
                    <Text>SaveDictLocally</Text>
                </TouchableHighlight>
                <TouchableHighlight style={{padding: 20, backgroundColor: '#ccc'}}
                                    onPress={() =>this.handlerReadLocally()  }>
                    <Text>ReadLocally</Text>
                </TouchableHighlight>
                <TouchableHighlight style={{padding: 20, backgroundColor: '#ccc'}}
                                    onPress={() =>this.handlerReadMapLocally()  }>
                    <Text>ReadMapLocally</Text>
                </TouchableHighlight>

            </View>
        );
    }
}
var styles = StyleSheet.create({
    container: {
        //   justifyContent: 'center',
        flex: 1,
        flexDirection: 'column',//没有flexDirection这个属性的话，justifyContent不会生效
        justifyContent: 'center',
        padding: 15,
        alignItems: 'center'
    }
});
AppRegistry.registerComponent('TestDBManager', () => TestDBManager);